Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
Running a "for" loop in JavaScript through Python-Selenium?

I use Javascript to collate data from an HTML page via Selenium; however, I cannot run the Javascript portion from my computer via Selenium/py cause Python only offers the driver.execute_script('string of a script'), whereas I have a multi-line for loop which won't execute with these commands.

The loop:

for (let i = 0; i < Values.length; i++) {
    if (Values[i].getAttribute('automation-id') === 'contact-wealth-manager') {
        ele = Values[i]
    }
}

As you can test, this won't work with the standard "driver.execute_script("let value = '';")

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To execute the multiline loop Javascript you need to pass the script as an argument to execute_script() method as follows:

driver.execute_script("""
    for (let i = 0; i < Values.length; i++) {
        if (Values[i].getAttribute('automation-id') === 'contact-wealth-manager') {
            ele = Values[i]
        }
    }
""")
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda